package com.jy.wms.dao;

import com.jy.wms.common.base.BaseDao;
import com.jy.wms.pojo.WmsBox;
import com.jy.wms.pojo.WmsReview;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
   * @ClassName: WmsReviewMapper.java
   * @Description: TODO(这里用一句话描述这个类的作用)
   * @Author Jane
   * @Date Tue Jan 30 10:19:46 CST 2018
   */
    @Mapper
   public interface WmsReviewMapper extends BaseDao<WmsReview> {

    @Select("<script>" +
            "SELECT shi.cyslb AS cyslb,box.id,box.num,box.zslx,box.xbh AS xbh,shi.fybh AS fybh,shi.lxrxm AS lxr,shi.lxrdh AS lxrdh,shi.sheng AS sheng,shi.shi AS shi,shi.khdz AS dz,box.sl AS sl,goodsType.mc AS goodsTypes,box.llzl AS zl,box.sjzl,packDet.tj * box.sl AS tj,(SELECT d_name from sys_dictionary where d_type='wms_shipment_order_cyslb' AND d_value=shi.cyslb) AS show_cyslb " +
            "FROM wms_box AS box LEFT JOIN wms_shipment_order_detailed AS shiDet ON box.ssfymxid = shiDet.id " +
            "LEFT JOIN wms_shipment_order AS shi ON shiDet.ssfyddid = shi.id " +
            "LEFT JOIN wms_goods AS goods ON shiDet.hpid = goods.id " +
            "LEFT JOIN wms_goods_type AS goodsType ON goods.zlid = goodsType.id " +
            "LEFT JOIN wms_packing AS pack ON goods.bzid = pack.id " +
            "LEFT JOIN wms_packing_detailed AS packDet ON packDet.ssbzid = pack.id AND packDet.bzlx = '0' " +
            "WHERE shiDet.ssfyddid IN " +
            "<foreach collection='list' index='index' item='item' open='(' separator=',' close=')'> " +
            "#{item}" +
            "</foreach>" +
            "GROUP BY ssfyddid,xxh " +
            "ORDER BY shi.cjsj DESC"+
            "</script>")
       public List<Map<String,Object>> zxPrintByFyIds(@Param("list") List<String> list);

    @Select("<script>" +
            "SELECT shi.cyslb AS cyslb,box.id,box.num,box.zslx,box.xbh AS xbh,shi.fybh AS fybh,shi.lxrxm AS lxr,shi.lxrdh AS lxrdh,shi.sheng AS sheng,shi.shi AS shi,shi.khdz AS dz,box.sl AS sl,goodsType.mc AS goodsTypes,box.llzl AS zl,box.sjzl,packDet.tj * box.sl AS tj,(SELECT d_name from sys_dictionary where d_type='wms_shipment_order_cyslb' AND d_value=shi.cyslb) AS show_cyslb " +
            "FROM wms_box AS box LEFT JOIN wms_shipment_order_detailed AS shiDet ON box.ssfymxid = shiDet.id " +
            "LEFT JOIN wms_shipment_order AS shi ON shiDet.ssfyddid = shi.id " +
            "LEFT JOIN wms_goods AS goods ON shiDet.hpid = goods.id " +
            "LEFT JOIN wms_goods_type AS goodsType ON goods.zlid = goodsType.id " +
            "LEFT JOIN wms_packing AS pack ON goods.bzid = pack.id " +
            "LEFT JOIN wms_packing_detailed AS packDet ON packDet.ssbzid = pack.id AND packDet.bzlx = '0' " +
            "WHERE box.id IN " +
            "<foreach collection='list' index='index' item='item' open='(' separator=',' close=')'> " +
            "#{item}" +
            "</foreach>" +
            "GROUP BY ssfyddid,xxh " +
            "</script>")
    public List<Map<String,Object>> zxPrintByXids(@Param("list") List<String> list);

    /**
     * 查询（根据箱编号查询集拼箱的IDS）
     *
     * @param xbh 箱编号
     * @return User
     */
    public List<String> baseSelectByPrimaryXbh(@Param("xbh") String xbh);

    /**
     * 根据 箱编号 仓库ID  发运单ID 查询集拼箱ID
     * @param xbh
     * @param ckid
     * @return
     */
    public String getBoxByXbh(@Param("xbh") String xbh, @Param("ckid") String ckid);

    /**
     * 更新 wms_picking 表内的fhzt内容
     * @param map
     * @return
     */
       public Integer updatePickingFhzt(@Param("map") Map<String, Object> map);
    public Integer updatePickingFhzts(@Param("map") Map<String, Object> map);

    /**
     * 根据箱编号 查询 复核信息
     * @param xbh
     * @param ckid
     * @return
     */
       public WmsReview getByXbh(@Param("xbh") String xbh, @Param("ckid") String ckid);

    /**
     * 根据箱编号查询承运商类别(装箱情况下)
     * @param xbh
     * @return
     */
    public Map<String,Object> getCyslbByZx(@Param("xbh") String xbh);

    /**
     * 根据箱编号获取箱信息
     * @param xbh
     * @return
     */
    public Map<String,Object> getXxx(@Param("xbh") String xbh);

    /**
     * 根据箱编号查询承运商类别(集拼箱情况下)
     * @param xbh
     * @return
     */
    public String getCyslbByJpx(@Param("xbh") String xbh);

    /**
     * 根据箱编号查询是否存在重复数据
     * @param xbh
     * @return
     */
       public Integer getCountByXbh(@Param("xbh") String xbh, @Param("ckid") String ckid);

    /**
     * 根据箱编号及仓库ID获取 装箱明细信息
     * @param xbh
     * @param ckid
     * @return
     */
   public List<Map<String,Object>> getZxmx(@Param("xbh") String xbh, @Param("ckid") String ckid);

    /**
     * 根据箱编号及仓库ID获取 装箱明细信息
     * @param xbh
     * @param ckid
     * @return
     */
    public List<Map<String,Object>> getZxmxZx(@Param("xbh") String xbh, @Param("ckid") String ckid);

    /**
     * 根据箱编号及仓库ID获取 集拼箱装箱明细信息
     * @param xbh
     * @param ckid
     * @return
     */
    public List<Map<String,Object>> getJpxMx(@Param("xbh") String xbh, @Param("ckid") String ckid);

    /**
     * 根据货品的ids 查询对应的种类 用 、 分隔
     * @param list
     * @return
     */
    public String getGoodsType(@Param("list") Set<String> list);

   /**
    * 插入一条记录
    * @param entity 实体对象
    * @return int
    */
    public Integer baseInsert(@Param("WmsReview") WmsReview entity);

    /**
     * 插入多条记录
     * @param list 实体对象
     * @return int
     */
    public Integer baseInsertAll(@Param("list") List<WmsReview> list);

   /**
    * 插入一条记录（匹配有值的字段）
    * @param entity 实体对象
    * @return int
    */
   public Integer baseInsertSelective(@Param("WmsReview") WmsReview entity);

   /**
    * 删除（根据主键ID删除）
    * @param id 主键
    * @return int
    */
   public Integer baseDeleteByPrimaryKey(@Param("id") String id);

   /**
    * 删除（根据ID 批量删除）
    * @param idList 主键ID列表
    * @return int
    */
    public Integer baseDeleteBathPrimaryKeys(@Param("list") List<String> idList);


    /**
    * 分页查询
    * @param entity 实体
    * @return List<WmsReview>
    */
    public List<Map<String,Object>> baseSelectPage(@Param("WmsReview") WmsReview entity);

    /**
    * 查询（根据主键ID查询）
    * @param id 主键ID
    * @return User
    */
    public WmsReview baseSelectByPrimaryKey(@Param("id") String id);

   /**
    * 查询（根据ID 批量查询）
    * @param idList 主键ID列表
    * @return list
    */
    public Integer baseSelectBathPrimaryKeys(@Param("list") List<WmsReview> idList);

   /**
    *修改 （匹配有值的字段）
    * @param entity 主键ID列表
    * @return int
    */
    public Integer baseUpdateByPrimaryKeySelective(@Param("WmsReview") WmsReview entity);

   /**
    *修改（根据主键ID修改）
    * @param entity 主键ID列表
    * @return int
    */
    public Integer baseUpdateByPrimaryKey(@Param("WmsReview") WmsReview entity);

    /**
     * 更新 装箱表内实际重量
     * @param map
     * @return
     */
    public Integer boxUpdate(@Param("map") Map<String, Object> map);
    public Integer boxUpdates(@Param("map") Map<String, Object> map);
    /**
     * 更新 装箱表内实际重量 根据集拼箱ID
     * @param map
     * @return
     */
    public Integer boxUpdateByJpxid(@Param("map") Map<String, Object> map);
    public Integer boxUpdateByJpxids(@Param("map") Map<String, Object> map);
    /**
     * 修改打印次数
     * @param num 次数
     * @param xbh  箱编号
     * @return
     */
    public Integer updateNum(@Param("num") Integer num, @Param("xbh") String xbh);

    /**
     *  根据箱编号获取整箱
     * @param xbh
     * @return
     */
    public List<WmsBox> getBox(String xbh);
}
